1375C - Element Extermination - CodeForces Solution


constructive algorithms data structures greedy *1400

Please click on ads to support us..

Python Code:

from sys import stdin
import math

t = int(stdin.readline().rstrip())
for _ in range(t):
    stdin.readline()
    nums = list(map(int, stdin.readline().rstrip().split(' ')))
    l = 0
    r = 1

    ans = True
    while r < len(nums):
        found = False
        while r < len(nums):
            if (nums[l] < nums[r]):
                found = True
                r += 1
                break
            r += 1
        
        if not found:
            ans = False
            break
            
    print('YES' if ans else 'NO')

C++ Code:

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int tc;
    cin>>tc;
    string ans[]= {"NO","YES"};
    while(tc--)
    {
        int n;
        bool b=0;
        cin>>n;
        int x[n];
        for(int i=0;i<n;i++)
            cin>>x[i];
        b=(x[n-1]>x[0]);
        cout<<ans[b]<<endl;

    }

    return 0;
}


Comments

Submit
0 Comments
More Questions

1469A - Regular Bracket Sequence
919C - Seat Arrangements
1634A - Reverse and Concatenate
1619C - Wrong Addition
1437A - Marketing Scheme
1473B - String LCM
1374A - Required Remainder
1265E - Beautiful Mirrors
1296A - Array with Odd Sum
1385A - Three Pairwise Maximums
911A - Nearest Minimums
102B - Sum of Digits
707A - Brain's Photos
1331B - Limericks
305B - Continued Fractions
1165B - Polycarp Training
1646C - Factorials and Powers of Two
596A - Wilbur and Swimming Pool
1462B - Last Year's Substring
1608B - Build the Permutation
1505A - Is it rated - 2
169A - Chores
765A - Neverending competitions
1303A - Erasing Zeroes
1005B - Delete from the Left
94A - Restoring Password
1529B - Sifid and Strange Subsequences
1455C - Ping-pong
1644C - Increase Subarray Sums
1433A - Boring Apartments